package com.example.smartf.controller;

import com.example.smartf.model.mysql.Trainmodel;
import com.example.smartf.service.TrainmodelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 关于设备 进行机器学习后
 * 产出的训练模型
 * 提供展示 和 删除模型操作
 */
@Api("设备模型")
@CrossOrigin(origins = "*")
@RestController
public class TrainmodelController {

    @Autowired
    private TrainmodelService trainmodelService;

    @ApiOperation("显示一个设备 对应的所有训练模型")
    @ApiImplicitParam(name = "deviceID", value = "设备ID", dataType = "String",paramType = "query")
    @PostMapping(value = "/trainmodel/show")
    List<Trainmodel> showTrainmodel(@RequestParam("deviceID") String deviceID){
        return trainmodelService.showTrainmodel(deviceID);
    }

    @ApiOperation("按照显示的ID 选择一个训练模型ID 进行删除")
    @ApiImplicitParam(name = "modelID", value = "模型ID", dataType = "String",paramType = "query")
    @PostMapping(value = "/trainmodel/del")
    String delTrainmodel(@RequestParam("modelID") String modelID){
        return trainmodelService.delTrainmodel(modelID);
    }

    @ApiOperation("使用模型预测")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelID",value = "模型ID",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "co2",value = "二氧化碳浓度", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "rh",value = "湿度", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "temp",value = "温度", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "light",value = "光照强度", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "lighttime",value = "光照时长", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "ec",value = "营养液浓度", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "ph",value = "ph值", dataType = "String",paramType = "query"),
    })
    @PostMapping(value = "/trainmodel/prediction")
    Double modelPrediction(String modelID,String co2,String rh,String temp, String light,String lighttime,String ec,String ph){
        return trainmodelService.modelPrediction(modelID,co2,rh,temp,light,lighttime,ec,ph);
    }
}
